package com.qf.dao.Impl;/*
    Dell
    2021/10/9
    9:26
*/

import com.qf.dao.UserDao;
import com.qf.entiy.User;
import com.qf.util.DruidUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    private QueryRunner queryRunner = new QueryRunner();
    @Override
    public User selectUser(String account) {
        try {
            return queryRunner.query(DruidUtil.getConnection(),"select * from user where account= ?;", new BeanHandler<>(User.class),account);
        } catch (SQLException e) {
            throw new RuntimeException(e.getMessage()+":查询用户是否存在出现异常");
        }
    }

    @Override
    public int update(String upassword, Integer uid) {
        try {
            return queryRunner.update(DruidUtil.getConnection(),"update user set password = ? where id = ?;", upassword,uid);
        } catch (SQLException e) {
            throw new RuntimeException(e.getMessage()+":修改密码出现异常");
        }
    }
}
